# -*- coding: utf-8 -*-
import os
import sys
import pyautogui
from core.maflagimg import MAFlagImg

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

screen_width, screen_height = pyautogui.size()

win_width = 690
card_width = win_width-30
win_height = 850

# version
VERSION = "2.0.11"
PROJECT = "mhbby"
WINTITLE = f"{PROJECT} {VERSION}"

# 截图存档目录
appdata_path = os.path.join(os.getenv('APPDATA'), r'mhxyQA')
appdata_user_ini = os.path.join(appdata_path, r'user.ini')
appdata_setting_ini = os.path.join(appdata_path, r'setting.ini')
appdata_annc_ini = os.path.join(appdata_path, r'annc.ini')

img_dir_path = resource_path(r'images')
shot_dir_path = resource_path(r'images/shot')
flag_dir_path = resource_path(r'images/flag')
flag_wp_dir_path = resource_path(r'images/flag/wp')
flag_tag_dir_path = resource_path(r'images/flag/tag')
flag_match_dir_path = resource_path(r'images/match')
flag_miss_dir_path = resource_path(r'images/miss')
map_dir_path = resource_path(r'images/map')

config_dir_path = resource_path(r'config')
subscribe_ini = os.path.join(config_dir_path, r'subscribe.ini')
shot_rect_ini = os.path.join(config_dir_path, r'shotrect.ini')
price_ini = os.path.join(config_dir_path, r'price.ini')

flag_audio_dir_path = resource_path(r'audio')

log_path = resource_path(r"logs")


#global
develop_mode = False

#shot rect
coord_shot_rect_default = [650, 190, 780, 280]
qa_shot_rect_default = [
    [140, 230, 670, 300],
    [280, 230, 700, 330],
    [180, 230, 700, 330],
    [150, 350, 700, 400],
    [290, 220, 710, 320],
    [140, 230, 670, 300],
]

qa_shot_rect = qa_shot_rect_default.copy()
coord_shot_rect = coord_shot_rect_default.copy()

#icon
icon_dir_path = resource_path(r'favicon.png')

# dt
DT_QA_LIST_NUM = 20

#subscribe
SUBSCRIBE_INTERVAL = 8

#auto
AUTO_INTERVAL = 1

#flag tag
flag_tag_fighting_cropbox = (793,182,805,436)
flag_tag_fighting = [
    os.path.join(flag_tag_dir_path, r'fighting_flag.jpg'),
    os.path.join(flag_tag_dir_path, r'fighting_flag2.png'),
]

flag_tag_mouse_name = [MAFlagImg('mouse_flag_1.jpg', -18, -15), MAFlagImg('mouse_flag_2.jpg', -18, -15), MAFlagImg('mouse_flag_3.jpg', -18, -15)]
flag_tag_mouse = [MAFlagImg(os.path.join(flag_tag_dir_path, name.img), name.offset_x, name.offset_y) for name in flag_tag_mouse_name]

flag_tag_panel_cropbox = (700,182,805,436)

#tips
TIPS_MAIN_SERVER = "<font color='red'>服务器公告</font>"
TIPS_MAIN_SPONSOR = "<font color='green'></font>"
TIPS_MAIN_ALERT = """为了您的游戏账户安全请从<a href="https://gitee.com/firemage/mhxyQA_GUI">官网</a> ,更新下载使用本软件。<br>请注意：使用本软件前，请确保您已了解相关风险，并愿意自行承担。"""
TIPS_QA_ALERT = """<font color='red'>请不要遮挡问题窗口！</font>"""
TIPS_SUBSCRIBE_ALERT = """<font color='red'>请不要遮挡监测窗口！</font>"""
TIPS_COORD_ALERT = """<font color='red'>请不要遮挡任务栏窗口！<br>仅开启一个任务显示和游戏设置色弱模式都可以提升识别成功率</font>"""
TIPS_CHARACTER_ALERT = """<font color='red'>仅供参考！仅供参考！仅供参考！</font>"""
TIPS_INVATATION = """<p>当新成员使用您的邀请码成功注册后，您将获得软件更高级别的权限以及<br>新功能的优先体验机会。这不只是开启更深层次软件功能的钥匙，更是加<br>入我们共同探索和成长社区的入场券。让我们一起携手，将这份独特的体验<br>分享给每一位新朋友，共同享受软件带来的无限可能。</p>"""
TIPS_OCR = """OCR 目前仅支持800x600分辨率"""
#announcement
annc_server = TIPS_MAIN_SERVER
annc_sponsor = TIPS_MAIN_SPONSOR

#exp
exp_ip = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
exp_port = "^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"

# request
REQUEST_TIMEOUT = 5
REQUEST_TIMEOUT_LONG = 10

# remote qa
URL_QA = ""
def URL_QA_OCR():
    return f"{URL_QA}/mhxyqa/ocr"

def URL_QA_SEARCH():
    return f"{URL_QA}/mhxyqa/search"

def URL_QA_SIGNUP():
    return f"{URL_QA}/mhxyqa/signup"

def URL_QA_SIGNIN():
    return f"{URL_QA}/mhxyqa/signin"

def URL_QA_SUBSCRIBE():
    return f"{URL_QA}/mhxyqa/subscribe"

def URL_QA_COORD():
    return f"{URL_QA}/mhxyqa/coord"

URL_IMAGE = "https://175dt.com/"

#ini
INI_USER_SECTION = "USER"
INI_USER_OPTION_USERNAME = "USERNAME"
INI_USER_OPTION_EMAIL = "EMAIL"
INI_USER_OPTION_TOKEN = "TOKEN"
INI_USER_OPTION_INVITATION = "INVITATION"

INI_SETTING_SECTION = "SETTING"
INI_SETTING_OPTION_IP = "IP"
INI_SETTING_OPTION_PORT = "PORT"
INI_SETTING_OPTION_VERSION = "VERSION"

INI_ANNC_SECTION = "ANNC"
INI_ANNC_OPTION_SERVER = "SERVER"
INI_ANNC_OPTION_SPONSOR = "SPONSOR"

INI_SUBSCRIBE_SECTION = "KEYWORD"

INI_SHOTRECT_SECTION = "SHOTRECTS"
INI_SHOTRECT_OPTION_QA = "QA"
INI_SHOTRECT_OPTION_COORD = "COORD"

INI_PRICE_SECTION = "KEYWORD"